﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;

using GDBLL.Config.Model;
using GDBLL.Cache;
using GDBLL.Config.BLL;

namespace GDBLL.Config.Control
{
    public class CachedConfigProvider : IConfigProvider
    {
        public CachedConfigProvider(ICacheStrategy cacheStrategy)
        {
            m_cacheStrategy = cacheStrategy;
        }

        private ICacheStrategy m_cacheStrategy;

        private readonly String CacheGrundInfo = "GrundInfo";//基础配置类

        public GrundInfo LoadGrundInfo()
        {

            GrundInfo t = m_cacheStrategy.RetrieveObject(CacheGrundInfo) as GrundInfo;

            if (t==null)
            {
                t = ConfigBLL.LoadGrundInfo();

                m_cacheStrategy.AddObjectWithFileChange(CacheGrundInfo, t, new string[] { ConfigBLL.GrundinfoPath });

                //_cache.Add(CacheGrundInfo, t, new System.Web.Caching.CacheDependency(ConfigManager.grundinfo_path)
                //    , DateTime.MaxValue, new TimeSpan(), System.Web.Caching.CacheItemPriority.Normal, null);

            }
            return t;
        }
    }
}
